package com.hongji.lms5xxcommunicator.grid.config;

import com.hongji.lms5xxcommunicator.grid.core.UpdateMode;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 读取 application.yml 中以 "grid" 开头的配置
 *
 * 示例：
 * grid:
 *   spec: {x0: 0, x1: 1000, y0: 0, y1: 1000, dx: 5, dy: 5}
 *   update-mode: REPLACE_SINGLE_ELSE_MEAN
 *   pad: 100 # 自动扩容留白（单位与 x/y 一致），可选
 *   volume: {baseline: 0.0, clamp-negative: true}
 *   regions:
 *     s1: {x0: 10, x1: 100, y0: 20, y1: 120}
 *     s2: {x0: 120, x1: 200, y0: 20, y1: 120}
 *     s3: {x0: 220, x1: 300, y0: 20, y1: 120}
 */
@Component
@ConfigurationProperties(prefix = "grid")
@Getter
@Setter
public class GridProps {

    /** 网格规格：边界与分辨率 */
    private Spec spec;

    /** 更新策略（可选），不配置则在 RasterGrid 内部默认 MEAN */
    private UpdateMode updateMode;

    /** 体积参数（可选） */
    private Volume volume;

    /** 自动扩容的留白（可选，默认 null；业务侧读取时可做 Math.max(0, pad)） */
    private Double pad;

    @Getter @Setter
    public static class Spec {
        private double x0, x1, y0, y1, dx, dy;
    }

    @Getter @Setter
    public static class Volume {
        private double baseline;
        private Boolean clampNegative; // 可为 null
    }
}
